package com.ruoyi.web.controller.medicine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.MedicineFactory;
import com.ruoyi.service.IHisMedicineFactory;
import com.ruoyi.system.domain.SysPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author rk
 * @description: TODO
 * @date 2024/8/28 20:34
 */
@RestController
@RequestMapping("medicine/factory")
public class MedicineController extends BaseController {
    @Autowired
    private IHisMedicineFactory hisMedicineFactory;

    /**
     *
     */
    @PreAuthorize("@ss.hasPermi('medicine:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineFactory medicineFactory)
    {
        startPage();
        List<MedicineFactory> list = hisMedicineFactory.selectFactoryList(medicineFactory);
        return getDataTable(list);
    }

    /**
     * 根据岗位编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:factory:list')")
    @GetMapping(value = "/list/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(hisMedicineFactory.selectFactoryById(id));
    }



    @PreAuthorize("@ss.hasPermi('medicine:factory:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody MedicineFactory medicineFactory)
    {
        medicineFactory.setCreateBy(getUsername());
        return toAjax(hisMedicineFactory.addFactory(medicineFactory));
    }

    /**
     * 修改岗位
     */
    @PreAuthorize("@ss.hasPermi('medicine:factory:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody MedicineFactory medicineFactory)
    {
        medicineFactory.setUpdateBy(getUsername());
        return toAjax(hisMedicineFactory.updateFactory(medicineFactory));
    }

    /**
     * 删除岗位
     */
    @PreAuthorize("@ss.hasPermi('medicine:factory:remove')")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(hisMedicineFactory.deleteFactoryById(id));
    }


    @PreAuthorize("@ss.hasPermi('medicine:factory:list')")
    @GetMapping(value = "/listAll")
    public AjaxResult getInfoAll()
    {
        return success(hisMedicineFactory.selectFactoryAll());
    }
}
